// app.js
import { get, post, upload } from './utils/ajax';
import { dateFormat, dateTimeFormat, formatTime } from './utils/utils';
App({
    onLaunch() {
        //this.httpLogin();
    },
    globalData: { },
    getImageUrl: (url) => {
		return `http://localhost:9000${url}`;
	},
	httpPost: post,
	httpGet: get,
    httpUpload: upload,
    httpLogin: async () => {
        // 登录
        wx.login({
            success: (res) => {
                // 发送 res.code 到后台换取 openId, sessionKey, unionId
                get(`mini/login`, { code: res.code }).then(({ data }) => {
                    wx.setStorageSync('openid', data.openid);
                    get(`mini/getInfo/${data.openid}`).then((res) => {
                        wx.setStorageSync('userInfo', res.data);
                    });
                });
            }
        })
    },
    formatTime: (date, format) => formatTime(date, format),
    dateTimeFormat: (date) => dateTimeFormat(date),
    dateFormat: (date) => dateFormat(date),
});